import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path, { resolve } from 'path'
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"

// https://vitejs.dev/config/
export default defineConfig({
    server: {
        host: '0.0.0.0',
        // https: true,
        port: 8080,
        open: true
    },
    base: './',
    // plugins: [vue(), basicSSL()],
    plugins: [
        vue(),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
            // svgoOptions: isBuild,
            // default
            symbolId: "icon-[dir]-[name]"
        }),
    ],
    resolve: {
        //别名配置，引用src路径下的东西可以通过@如：import Layout from '@/layout/index.vue'
        alias: [
            {
                find: '@',
                replacement: resolve(__dirname, 'src')
            }
        ]
    },
    css: {},
    build: {
        outDir: "dist",  //指定输出文件
        assetsDir: "./",  //指定生成静态文件目录
        rollupOptions: {
            output: {
                chunkFileNames: "static/js/[name]-[hash].js",
                entryFileNames: "static/js/[name]-[hash].js",
                assetFileNames(assetInfo) {
                    if (assetInfo.name.endsWith('.css')) {
                        return "static/css/[name]-[hash].[ext]"
                    }
                    if (["png", "jpg", "svg", "PNG"].some(ext => assetInfo.name.endsWith(ext))) {
                        return "static/img/[name]-[hash].[ext]"
                    }
                    if (["ttf", "woff", "woff2"].some(ext => assetInfo.name.endsWith(ext))) {
                        return "static/fonts/[name]-[hash].[ext]"
                    }
                    return "static/css/[name]-[hash].[ext]"
                }
            }
        }
    }
})
